<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点击</button>
    <script>
        var that;//全局变量
        class Star{
            constructor(uname){
                that = this;//把对象实例ldh给全局变量that
                this.uname = uname;
                this.btn = document.querySelector('button');
                this.btn.onclick = this.sing;
            }
            sing(){
                console.log(this);//指向的是btn返回button 谁是调用者就返回谁
                console.log(that.uname);//相当于打印实例里面的uname
            }
        }
        var ldh = new Star('刘德华');

    </script>
</body>
</html>